/* Summary0.do (STATA)
	Summarize data.
	by Ralph Koijen & Motohiro Yogo */

#delimit ;
clear all;
set more off;
set type double;

cap log close;
log using Summary0, replace;


/* Step 1: List of countries */

/* Load data */

u year country country_Name country_group country_Ieuro type Iycountry
	if !inlist(country,"_CR","_OC") & type==3 & Iycountry
	using "../1 Data/Data4", clear;

/* Construct variables */

egen year_min = min(year), by(country);
egen year_max = max(year), by(country);

/* Keep one observation per country */

keep if year==year_max;

/* Output table */

gsort country_group -country_Ieuro country_Name;
l country_group country_Name year_min year_max, noobs clean;


/* Step 2: Summary of financial markets */

/* Load data */

u year Name group Ieuro type amount Iown I_CR Iycounterpart
	using "../1 Data/Data4", clear;

/* Construct variables */

egen market = total(amount), missing by(year Name type);

/* Share domestic owned */

egen domestic = total(amount/market*Iown), missing by(year Name type);

drop Iown;

/* Share in currency reserves */

egen reserve = total(amount/market*I_CR), missing by(year Name type);

drop amount I_CR;

/* Keep one observation per country */

keep if year==2020 & Iycounterpart;

/* Output table */

gsort type group -Ieuro Name;
by type: l group Name market domestic reserve, noobs clean;


/* Step 3: Top 10 investor countries */

/* Load data */

u year country_Name type wealthA Iycountry
	if year==2020 & Iycountry
	using "../1 Data/Data4", clear;

/* Output table */

gsort type -wealthA;
by type: l country_Name wealthA if _n<=10, noobs clean;

log close;
